home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / docs / ippon / ver / 050 / player.c < prev    next >
C/C++ Source or Header  |  2000-07-07  |  7KB  |  288 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8. #include "shot.h"
  9. #include "effect.h"
  10. #include "sound.h"
  11.  
  12. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  13. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  14.  
  15. #define PLAYER_SPEED    15    /* 自機の速度 */
  16. #define PLAYER_PALET    0x0700    /* 自機のパレット */
  17.  
  18. #define PLAYER_START_X    144    /* 自機出現時の座標 */
  19. #define PLAYER_START_Y    (256+32)
  20.  
  21. #define PLAYER_MINX        (16+8)    /* X 座標最小値 */
  22. #define PLAYER_MAXX        (16+255-8)
  23. #define PLAYER_MINY        (16+16)        /* Y 座標最小値 */
  24. #define PLAYER_MAXY        (16+255-12)
  25.  
  26. #define    TIME_MUTEKI    90    /* 登場時の無敵時間 */
  27.  
  28. enum {
  29.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  30.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  31.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  32.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  33.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  34. };
  35.  
  36.  
  37.  
  38. /* ゲーム開始時に呼ばれる */
  39. void PlayerInit (void)
  40. {
  41. }
  42.  
  43.  
  44.  
  45. /* プレイヤー出現時に呼ばれる */
  46. void PlayerAlloc (void)
  47. {
  48.     player->lx = PLAYER_START_X * 65536;
  49.     player->ly = PLAYER_START_Y * 65536;
  50.     player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  51.     player->counter = 0;
  52.     player->muteki = TIME_MUTEKI;
  53.     player->flash = 0;
  54. }
  55.  
  56.  
  57.  
  58. /* 自機が生きている時の移動処理 */
  59. static void PlayerMoveAlive (void)
  60. {
  61.     int j;            /* ジョイスティックの入力 */
  62.  
  63.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  64.  
  65.     /* [A] ボタンが押されたか? */
  66.     if ((j & 0b00100000) == 0)
  67.         game_over = !0;    /* ゲームオーバーに */
  68.  
  69.     /* [B] ボタンが押されたか? */
  70.     if ((j & 0b1000000) == 0)
  71.         ShotAlloc ();
  72.  
  73.     /* 自機の上下移動処理 */
  74.     switch (j & 0b0011) {
  75.     case 0b0010:        /* 上 */
  76.         if (player->ly >> 16 > PLAYER_MINY)
  77.             player->ly += xytable[PLAYER_SPEED][192].y;
  78.         break;
  79.     case 0b0001:        /* 下 */
  80.         if (player->ly >> 16 < PLAYER_MAXY)
  81.             player->ly += xytable[PLAYER_SPEED][64].y;
  82.         break;
  83.     default:        /* それ以外 */
  84.         break;
  85.     }
  86.  
  87.     /* 自機の左右移動処理+左右傾き処理 */
  88.     switch (j & 0b1100) {
  89.     case 0b1000:        /* 左 */
  90.         if (player->lx >> 16 > PLAYER_MINX)
  91.             player->lx += xytable[PLAYER_SPEED][128].x;
  92.         if (player->bank > 0) {
  93.             player->bank = 0;
  94.         } else {
  95.             if (player->bank > -PLAYER_BANK2)
  96.                 player->bank--;
  97.         }
  98.         break;
  99.  
  100.     case 0b0100:        /* 右 */
  101.         if (player->lx >> 16 < PLAYER_MAXX)
  102.             player->lx += xytable[PLAYER_SPEED][0].x;
  103.         if (player->bank < 0) {
  104.             player->bank = 0;
  105.         } else {
  106.             if (player->bank < PLAYER_BANK2)
  107.                 player->bank++;
  108.         }
  109.         break;
  110.  
  111.     default:        /* それ以外 */
  112.         /* 自機の傾きを元に戻す処理 */
  113.         if (player->bank != 0) {
  114.             if (player->bank > 0)
  115.                 player->bank--;
  116.             else
  117.                 player->bank++;
  118.         }
  119.         break;
  120.     }
  121.  
  122.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  123.     if (player->bank == 0) {
  124.         player->pt = obj_player + PLAYER_PT_CENTER;
  125.     } else {
  126.         if (player->bank > 0) {
  127.             if (player->bank < PLAYER_BANK1)
  128.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  129.             else
  130.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  131.         } else {
  132.             if (player->bank > -PLAYER_BANK1)
  133.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  134.             else
  135.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  136.         }
  137.     }
  138.  
  139.     player->x = player->lx / 65536;
  140.     player->y = player->ly / 65536;
  141.  
  142.     /* 無敵状態の処理 */
  143.     player->info = PALET_PLAYER | PRIORITY_PLAYER;
  144.     if (player->muteki) {
  145.         player->muteki--;
  146.         player->flash++;
  147.         if (player->muteki > 55) {
  148.             /* バリアが沢山残っているので速いフラッシュ */
  149.             if (player->flash > 1) {
  150.                 player->info = PALET_PLAYER_FLASH | PRIORITY_PLAYER;
  151.                 player->flash = 0;
  152.             }
  153.         } else {
  154.             /* バリアが少ししかないので遅いフラッシュ */
  155.             if (player->flash > 5)
  156.                 player->info = PALET_PLAYER_FLASH | PRIORITY_PLAYER;
  157.             if (player->flash > 10)
  158.                 player->flash = 0;
  159.         }
  160.     }
  161.     xobj_set_st (player);    /* 自機を表示 */
  162. }
  163.  
  164.  
  165. /* 自機が死んだ時の移動処理 */
  166. static void PlayerMoveDead (void)
  167. {
  168.     /* 自機の傾きを元に戻す処理 */
  169.     if (player->bank != 0) {
  170.         if (player->bank > 0)
  171.             player->bank--;
  172.         else
  173.             player->bank++;
  174.     }
  175.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  176.     if (player->bank == 0) {
  177.         player->pt = obj_player + PLAYER_PT_CENTER;
  178.     } else {
  179.         if (player->bank > 0) {
  180.             if (player->bank < PLAYER_BANK1)
  181.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  182.             else
  183.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  184.         } else {
  185.             if (player->bank > -PLAYER_BANK1)
  186.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  187.             else
  188.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  189.         }
  190.     }
  191.  
  192.     player->info = PALET_PLAYER | PRIORITY_PLAYER;
  193.     switch (player->counter++) {
  194.     case 0:
  195.         /* 今死んだところなら爆発パターンを出す */
  196.         EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x, player->y);    /* 爆発パターンを出現させる */
  197.         SoundSetSE (SE_PLAYER_EXPL);    /* プレイヤーの爆発音 */
  198.         break;
  199.     case 8 * 1:
  200.     case 8 * 2:
  201.     case 8 * 3:
  202.     case 8 * 4:
  203.     case 8 * 5:
  204.         {
  205.             signed short x, y;
  206.             x = rndtable[(player->counter) & 0xff ^ 0x55] - 128;
  207.             y = rndtable[(player->counter + 1) & 0xff ^ 0xaa] - 128;
  208.             /* player->counter は乱数の種として使用しています */
  209.             EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x + x / 8, player->y + y / 8);
  210.             SoundSetSE (SE_PLAYER_EXPL);    /* プレイヤーの爆発音 */
  211.         }
  212.         break;
  213.  
  214.     case 8 * 7:
  215.         /* 最後の「どっかーん」 */
  216.         EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x, player->y);
  217.         SoundSetSE (SE_EXPL_L);
  218.         player->x = 256 + 32;
  219.         player->y = 256 + 32;
  220.         break;
  221.     case 8 * 12:
  222.         /* 座標を初期化 */
  223.         player->lx = PLAYER_START_X * 65536;
  224.         player->ly = PLAYER_START_Y * 65536;
  225.         player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  226.         player->counter = 0;
  227. #if    0
  228.         player->rest--;
  229.         if (player->rest <= 0) {
  230.             player->game_over = GAME_OVER;
  231.         } else {
  232.             if (!eshot_erase)
  233.                 eshot_erase = ESHOT_ERASE;    /* 弾消し */
  234.         }
  235.         DispRest ();    /* 残機数表示 */
  236. #endif
  237.         break;
  238.  
  239.     default:
  240.         if (player->counter < 55)
  241.             xobj_set_st (player);    /* 自機を表示 */
  242.         break;
  243.     }
  244. }
  245.  
  246.  
  247.  
  248. /* 自機が死んだ後の登場処理 */
  249. static void PlayerMoveAppear (void)
  250. {
  251.     player->bank = 0;
  252.     player->pt = obj_player + PLAYER_PT_CENTER;
  253.     player->ly -= (4 * 65536);
  254.  
  255.     player->x = player->lx / 65536;
  256.     player->y = player->ly / 65536;
  257.  
  258.     /* 自機がある程度上まで進んだら通常状態へ */
  259.     if (player->y < 160) {
  260.         player->status = PLAYER_STATUS_ALIVE;
  261.         player->muteki = TIME_MUTEKI;
  262.     }
  263.     player->info = PALET_PLAYER | PRIORITY_PLAYER;
  264.     if (player->flash++ > 1) {
  265.         player->info = PALET_PLAYER_FLASH | PRIORITY_PLAYER;
  266.         player->flash = 0;
  267.     }
  268.     xobj_set_st (player);    /* 自機を表示 */
  269. }
  270.  
  271.  
  272.  
  273. /* 垂直同期ごとに呼ばれる */
  274. void PlayerMove (void)
  275. {
  276.     switch (player->status) {
  277.     case PLAYER_STATUS_ALIVE:
  278.         PlayerMoveAlive ();
  279.         break;
  280.     case PLAYER_STATUS_DEAD:
  281.         PlayerMoveDead ();
  282.         break;
  283.     case PLAYER_STATUS_APPEAR:
  284.         PlayerMoveAppear ();
  285.         break;
  286.     }
  287. }
  288.